package com.lagou.homework131;

/**
 * 编程统计字符串"ABCD123!@#$%ab"中大写字母、小写字母、数字、其它字符的个数并打印出来。
 */
public class CharStatistics {
    private static final String str = "ABCD123!@#$%ab";


    public static void main(String[] args) {

        StringBuilder upperCase = new StringBuilder();
        StringBuilder lowerCase = new StringBuilder();
        StringBuilder number = new StringBuilder();
        StringBuilder otherChar = new StringBuilder();


        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                upperCase.append(c);
            } else if (c >= 'a' && c <= 'z') {
                lowerCase.append(c);
            } else if (c >= '0' && c <= '9') {
                number.append(c);
            } else {
                otherChar.append(c);
            }
        }

        System.out.println("需要统计的字符串：" + str);
        System.out.println("大写字母：" + upperCase + "，共计" + upperCase.length() + "个");
        System.out.println("小写字母：" + lowerCase + "，共计" + lowerCase.length() + "个");
        System.out.println("数   字：" + number + "，共计" + number.length() + "个");
        System.out.println("其他字符：" + otherChar + "，共计" + otherChar.length() + "个");

    }


}
